| Conditions | 1 |
| Paths | 1 |
| Total Lines | 148 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var chai = require('chai'); |
||
| 21 | describe('Plugin', function() { |
||
| 22 | |||
| 23 | before( function(done) { |
||
| 24 | Manager.instance.init() |
||
| 25 | .then(function () { |
||
| 26 | this.fixture = { |
||
| 27 | testPlugin: 'test', |
||
| 28 | testNewPlugin: 'testnew', |
||
| 29 | testScript: 'test-script', |
||
| 30 | testProcess: 'test' |
||
| 31 | } |
||
| 32 | done() |
||
| 33 | }.bind(this)) |
||
| 34 | }); |
||
| 35 | |||
| 36 | it('abeExtend.hooks.instance.getPluginConfig find plugin', function(){ |
||
| 37 | const plugin = abeExtend.plugins.instance.getPluginConfig( |
||
| 38 | abeExtend.plugins.instance.pluginsDir, |
||
| 39 | this.fixture.testPlugin |
||
| 40 | ) |
||
| 41 | chai.expect(plugin.hooks).to.have.afterEditorInput; |
||
|
|
|||
| 42 | chai.expect(plugin.routes.get[0]).to.have.path; |
||
| 43 | }) |
||
| 44 | |||
| 45 | it('abeExtend.hooks.instance.getPluginConfig find script', function(){ |
||
| 46 | const plugin = abeExtend.plugins.instance.getPluginConfig( |
||
| 47 | abeExtend.plugins.instance.scriptsDir, |
||
| 48 | this.fixture.testScript |
||
| 49 | ) |
||
| 50 | chai.expect(plugin.hooks).to.have.afterEditorInput; |
||
| 51 | }) |
||
| 52 | |||
| 53 | it('abeExtend.hooks.instance.getProcess', function(){ |
||
| 54 | const proc = abeExtend.plugins.instance.getProcess( |
||
| 55 | this.fixture.testProcess |
||
| 56 | ) |
||
| 57 | chai.assert.equal(path.basename(proc), 'test.js', 'getProcess test failed !') |
||
| 58 | }) |
||
| 59 | |||
| 60 | it('abeExtend.hooks.instance.getPartials', function(){ |
||
| 61 | const partialsArray = abeExtend.plugins.instance.getPartials() |
||
| 62 | chai.assert.equal(partialsArray.length, 1, 'getPartials test failed !') |
||
| 63 | }) |
||
| 64 | |||
| 65 | it('abeExtend.plugins.instance.getRoutes()', function() { |
||
| 66 | var routes = abeExtend.plugins.instance.getRoutes() |
||
| 67 | chai.expect(routes[0].get).to.have.length(1); |
||
| 68 | }); |
||
| 69 | |||
| 70 | it('abeExtend.hooks.instance.trigger', function() { |
||
| 71 | var res = abeExtend.hooks.instance.trigger('afterEditorInput') |
||
| 72 | chai.assert.equal(res, 'test', 'Hook test failed !') |
||
| 73 | }); |
||
| 74 | |||
| 75 | it('abeExtend.plugins.instance.add', function(done) { |
||
| 76 | var dir = './node_modules/' |
||
| 77 | this.sinon = sinon.sandbox.create(); |
||
| 78 | var fakeChild = this.fakeChild = { |
||
| 79 | 'stdout': new events.EventEmitter(), |
||
| 80 | 'stderr': new events.EventEmitter() |
||
| 81 | }; |
||
| 82 | |||
| 83 | this.sinon.stub(child_process, 'spawn', function(){ |
||
| 84 | return fakeChild; |
||
| 85 | }); |
||
| 86 | |||
| 87 | abeExtend.plugins.instance.add(dir, this.fixture.testPlugin) |
||
| 88 | .then(function() { |
||
| 89 | chai.expect(child_process.spawn).to.have.been.calledWith(npm, ["install", "--save", this.fixture.testPlugin], { cwd: "./node_modules/" }) |
||
| 90 | done() |
||
| 91 | this.sinon.restore(); |
||
| 92 | }.bind(this)) |
||
| 93 | }); |
||
| 94 | |||
| 95 | it('abeExtend.plugins.instance.remove', function(done) { |
||
| 96 | var dir = './node_modules/' |
||
| 97 | this.sinon = sinon.sandbox.create(); |
||
| 98 | var fakeChild = this.fakeChild = { |
||
| 99 | 'stdout': new events.EventEmitter(), |
||
| 100 | 'stderr': new events.EventEmitter() |
||
| 101 | }; |
||
| 102 | |||
| 103 | this.sinon.stub(child_process, 'spawn', function(){ |
||
| 104 | return fakeChild; |
||
| 105 | }); |
||
| 106 | this.sinon.stub(abeExtend.plugins.instance, 'removePlugin') |
||
| 107 | |||
| 108 | abeExtend.plugins.instance.remove(dir, this.fixture.testNewPlugin) |
||
| 109 | .then(function() { |
||
| 110 | chai.expect(child_process.spawn).to.have.been.calledWith(npm, ["uninstall", "--save", this.fixture.testNewPlugin], { cwd: "./node_modules/" }) |
||
| 111 | done() |
||
| 112 | abeExtend.plugins.instance.removePlugin.restore() |
||
| 113 | this.sinon.restore(); |
||
| 114 | }.bind(this)) |
||
| 115 | }); |
||
| 116 | |||
| 117 | it('abeExtend.plugins.instance.removePlugin(plugin)', function() { |
||
| 118 | abeExtend.plugins.instance.removePlugin(this.fixture.testNewPlugin) |
||
| 119 | chai.assert.equal(config.getLocalConfig().plugins.length, 1, 'updatePlugin test failed !') |
||
| 120 | }); |
||
| 121 | |||
| 122 | it('abeExtend.plugins.instance.updatePlugin NoVersionNewPlugin', function() { |
||
| 123 | abeExtend.plugins.instance.updatePlugin(this.fixture.testNewPlugin) |
||
| 124 | chai.assert.equal(config.plugins[1], this.fixture.testNewPlugin, 'updatePlugin test failed !') |
||
| 125 | }); |
||
| 126 | |||
| 127 | it('abeExtend.plugins.instance.updatePlugin VersionExistingPlugin', function() { |
||
| 128 | abeExtend.plugins.instance.updatePlugin("[email protected]") |
||
| 129 | chai.assert.equal(config.plugins[0], '[email protected]', 'updatePlugin test failed !') |
||
| 130 | }); |
||
| 131 | |||
| 132 | it('abeExtend.plugins.instance.install(dir, plugin)', function(done){ |
||
| 133 | var dir = './node_modules/' |
||
| 134 | this.sinon = sinon.sandbox.create(); |
||
| 135 | var stub = sinon.stub(abeExtend.plugins.instance, 'add') |
||
| 136 | stub.returns(Promise.resolve(0)); |
||
| 137 | |||
| 138 | abeExtend.plugins.instance.install(dir, this.fixture.testPlugin) |
||
| 139 | sinon.assert.calledOnce(abeExtend.plugins.instance.add) |
||
| 140 | abeExtend.plugins.instance.add.restore() |
||
| 141 | done() |
||
| 142 | }); |
||
| 143 | |||
| 144 | it('abeExtend.plugins.instance.install(dir)', function(done){ |
||
| 145 | var dir = './node_modules/' |
||
| 146 | this.sinon = sinon.sandbox.create(); |
||
| 147 | var stub = sinon.stub(abeExtend.plugins.instance, 'add') |
||
| 148 | stub.returns(Promise.resolve(0)); |
||
| 149 | |||
| 150 | abeExtend.plugins.instance.install(dir) |
||
| 151 | sinon.assert.calledTwice(abeExtend.plugins.instance.add) |
||
| 152 | abeExtend.plugins.instance.add.restore() |
||
| 153 | |||
| 154 | done() |
||
| 155 | }); |
||
| 156 | |||
| 157 | it('abeExtend.plugins.instance.uninstall(dir, plugin)', function(done){ |
||
| 158 | var dir = './node_modules/' |
||
| 159 | this.sinon = sinon.sandbox.create(); |
||
| 160 | var stub = sinon.stub(abeExtend.plugins.instance, 'remove') |
||
| 161 | stub.returns(Promise.resolve(0)); |
||
| 162 | |||
| 163 | abeExtend.plugins.instance.uninstall(dir, this.fixture.testNewPlugin) |
||
| 164 | sinon.assert.calledOnce(abeExtend.plugins.instance.remove) |
||
| 165 | abeExtend.plugins.instance.remove.restore() |
||
| 166 | done() |
||
| 167 | }); |
||
| 168 | }); |
||
| 169 |